package com.example.pet.controller;

import com.hj.pet.api.UserService;
import com.hj.pet.model.Constant;
import com.hj.pet.model.ReturnT;
import com.hj.pet.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/internal/user")
@RestController
public class UserController {
    @Autowired
    UserService userService;

    @RequestMapping(value = "login",method = RequestMethod.POST)
    @ResponseBody
    public ReturnT<?> login(@RequestParam String userAccount, String userPwd) {
        System.out.println("account:"+userAccount);
        System.out.println("pwd:"+userPwd);
        User user = userService.doLogin(userAccount,userPwd);
        if (null != user){
            ReturnT<User> returnT = new ReturnT<>(Constant.SUCCESS_CODE);
            returnT.setData(user);

            return returnT;
        }else{
            return new ReturnT<>(Constant.FAIL_CODE,"登陆失败，用户名或密码不正确");
        }
    }

    @RequestMapping(value = "registry", method = RequestMethod.POST)
    @ResponseBody
    public boolean registry(@RequestParam String userAccount ,String userPwd){
        return userService.register(userAccount,userPwd);
    }
}
